package hbase;

import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.rest.client.Client;
import org.apache.hadoop.hbase.rest.client.Cluster;
import org.apache.hadoop.hbase.rest.client.RemoteHTable;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

/**
 * Created by spark on 16-10-22.
 */
public class RestTest {

    public static void main(String[] args) throws IOException {
        Cluster cluster = new Cluster();
        cluster.add("localhost", 8080);

        Client client = new Client(cluster);
        RemoteHTable table = new RemoteHTable(client, "joe");

        Get get = new Get(Bytes.toBytes("row007"));
        Result result = table.get(get);
        System.out.println(result);

        Scan scan = new Scan();
        scan.setStartRow(Bytes.toBytes("row002"));
        scan.setStopRow(Bytes.toBytes("row008"));
        ResultScanner scanner = table.getScanner(scan);
        for (Result temp : scanner) {
            System.out.println(temp);
        }

        table.close();
    }
}
